<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="com.webside.points.wechat.Wechat"%>  
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%
	 //正常跳转
	String code = (String)request.getParameter("code");
  
	String openId = null;
	
	if(code != null){
		Wechat.getOpenId(code,request,response);
	}
	
	if(openId == null){
		openId = (String)request.getSession().getAttribute("openId");
	}
	//如果从其他界面返回时，code已经失效，需要重新请求一次
	
	if(openId == null){
	   response.sendRedirect("../wechat/getWeChatCode");
	   return;
	}  
	
 %>
<%-- <% 
    request.getSession().setAttribute("openId", "oqxTFs9Z7Ef2HjwCeBnKGFHakGjs");
 	String openId=(String)request.getSession().getAttribute("openId");
 %> --%>
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <link rel="stylesheet" href="../css/amazeui.min.css">
  <link rel="stylesheet" href="../css/wap.css">
  <link rel="stylesheet" href="../css/style.css"/>
  <link rel="stylesheet" href="../css/weui.css" />
  <title>提问</title>
</head>
<script src="../js/jquery.min.js"></script>
  <script src="../js/amazeui.min.js"></script>
   <script type="text/javascript"
	src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  	<script src="../js/jssdk.js"></script>
  	<link rel="stylesheet" href="../css/dropload.css">
	<script src="../js/dropload.min.js"></script>
<script type="text/javascript">

	$(function(){
		
		$(function(){
			// 页数
			var page = 0;
			// 每页展示多少个
			var size = 10;
			var openId = $("#openId").val();
			var expertId = $("#expertId").val();
			
			// dropload
			$('.content').dropload({
				scrollArea : window,
				loadDownFn : function(me){
					page++;
					// 拼接HTML
					var result = '';
					$.ajax({
						type: 'post',
						url: '../issueType/findAllExpert?page='+page+"&size="+size,
						dataType: 'json',
						success: function(data){
							var arrLen = data.length;
							//alert(data);
							if(arrLen > 0){
								for(var i=0; i<arrLen; i++){
									//判断是否停用
									if(data[i].auditStatus==1){
										//不显示自己的
										if(data[i].id!=expertId){
											 result +=   '<div class="weui-cell">'
												+' <a href="${ctx}/expert/findExpertInfo?expertId='+data[i].id+'">'
													+'<span><img src="'+data[i].userEntity.headUrl+'" alt="" style="width:55px;height:55px;margin-right:10px;"> </span>'
												+'</a>'
												+' <span class="weui-cell__bd">'
												+'<span style="vertical-align: middle">'
													+'<div>'+data[i].name+'</div>'
													+' <div style="color:#969595;font-size:11px;" >'+data[i].workUnit+''+data[i].duty+'</div>'
													/*+' <div style="color:#969595;font-size:11px;white-space:nowrap;text-overflow: ellipsis;width:100px;overflow: hidden;" >'+data[i].speciality+'</div>'*/
													+' <div style="color:#969595;font-size:9px;" class="answerCount" id="'+data[i].id+'">0个回答</div>'
												+'</span>'
												+'</span>'
												+'<a href="${ctx }/service/character-issue.jsp?issueTypeId='+data[i].expertType+'&openId='+openId+'&expert='+data[i].id+'&type=issue">'
													+'<span style="border:1px solid #22ac38;color:#22ac38;padding:3px 8px;border-radius:5px;">向他提问</span>'
												+'</a>'
											+'</div>'
										}
										
									}
								}
													
							// 如果没有数据
							}else{
								// 锁定
								me.lock();
								// 无数据
								me.noData();
							}
							// 插入数据到页面，放到最后面
							$('.expert').append(result);
							// 每次数据插入，必须重置
							me.resetload();
							
							//异步获取专家回答数量
							$(".answerCount").each(function(){;
								var answerCountId =$(this).attr("id");
								var div = $(this);
								$.post("${ctx}/answer/findById", {"expertId":answerCountId}, function(data, status, xhr){
									 div.text(data.length+"个回答");
								},'json');
							});
		
						},
						error: function(xhr, type){
							//alert('Ajax error!');
							// 即使加载出错，也得重置
							me.resetload();
						}
					});
				}
			});
		});
	})
</script>
  <style type="text/css">
	.label{
		border: 1px solid #EDEDED;
		margin: 5px;
		padding: 2px 5px;
		border-radius: 5px;
		display:inline-block;
		font-size: 15px;
	}
	.issueType{
		width:49%;
		display:inline-block;
		text-align:center;
		background:#e60012;
		color:#fffefe;
		padding:15px 0px;
		margin-bottom:15px;
	}
	.issue-text-alert{
		font-size:12px;
		color:#969595;
		margin-top:10px;
		display:inline-block;
	}
	.issue-input{
		padding:15px 15px 45px 15px;
		text-align:center;
		border-bottom:1px solid #e5e5e5;
	}
	
  </style>
<body style="background:#ececec" >
  <div class="pet_mian" >
  <input type="hidden" value="<%=openId %>" id="openId">
  <input type="hidden" value="${user.expertId}" id="expertId">
   <!-- loading toast -->
    <div id="loadingToast" style="display:none;">
		<div class="weui-mask_transparent"></div>
		<div class="weui-toast">
			<i class="weui-loading weui-icon_toast"></i>
			<p class="weui-toast__content">数据加载中</p>
		</div>
	</div>
  
	<input type="hidden" id="result" value="${result}">
    <div class="pet_content pet_content_list pet_hd">
      <div class="pet_article_like">
        <div class="pet_content_main pet_article_like_delete">
          <div data-am-widget="list_news" class="am-list-news am-list-news-default am-no-layout">
            <div class="am-list-news-bd content">
					
				  <!--issueType-->
	           	  <div class="button-sp-area issue-input">
					<a href="${ctx }/service/character-issue.jsp?openId=<%=openId%>&type=issue"> 
						<input type="button" style="font-size:17px;" class="weui-btn weui-btn_primary" value="提问" >
					</a>
					<span class="issue-text-alert">向所有专家提问，等待抢答</span>
				  </div>
	               
	              <div class="expert">

	              </div>
              </div>
            </div>
          </div>
        </div>
      </div>
 <!--底部-->
    <div data-am-widget="navbar" class="am-navbar am-cf my-nav-footer " id="">
      <ul class="am-navbar-nav am-cf am-avg-sm-4 my-footer-ul">
		<li>
           <a href="${ctx }/user/findUserIssue?issueTypeId=0" class="">
            <span class="am-icon-home"></span>
            <span class="am-navbar-label">首页</span>
          </a>
        </li>
        <li>
          <a href="${ctx }/issueType/findAll?mark=service&openId=<%=openId %>" class="">
            <span class="am-icon-comments"></span>
            <span class="am-navbar-label">提问</span>
          </a>
        </li>
		<li>
          <a href="${ctx }/postType/findAllPostType" class="">
            <span class="am-icon-book"></span>
            <span class="am-navbar-label">学习</span>
          </a>
        </li>
        <li style="position:relative">
          <a href="${ctx }/user/findByOpenId?openId=<%=openId %>" class="">
            <span class="am-icon-user"></span>
            <span class="am-navbar-label">我的</span>
          </a>
        </li>
      </ul>
</div>
    </div>
  <script src="../js/amazeui.min.js"></script>
    <script src="../js/text-calculation.js"></script>
</body>
  </html>